/**
 * 
 */
package game.rwalk.utility;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

/**
 * @author sk8erboi
 *
 */
public class ProccessFile {
	
	InputStream stream;
	FileInputStream fileStream;

	public ProccessFile(InputStream is) {
		
		stream = is;
		
		
	}
	
	public ProccessFile(FileInputStream fis) {
		fileStream = fis;
	}
	
	public int[][] getIndex() {
		int[][] array = new int[5][3];
		
		try {
			
			int data = stream.read();
			int row = 0;
			int cell = 0;
			
			while(data != -1) {
				
				if(data == 10) {
					
					row++;
					cell = 0;
				} else if(data != 13) {
					switch((char) data) {
					case '0' :array[row][cell] =0;
						break;
					case '1' :array[row][cell] =1;
						break;
					case '2' :array[row][cell] =2;
						break;
					}
					
					cell++;
				}
				
				data = stream.read();
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
			
			return array;
	}
	
	public String[] getPlayer() {
		
		String[] names = new String[4];
		
//		try {
//			
//			int data = stream.read();
//			StringBuffer name = new StringBuffer("");
//			while(data != -1) {
//				name.append((char)data);
//				//System.out.println((char) data+ "   :   " +data);
//				
//				data = stream.read();
//			}
//			
//			System.out.println(name);
//		} catch (IOException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
		
		 if (fileStream!=null) {
		    InputStreamReader tmp=new InputStreamReader(fileStream);
		    BufferedReader reader=new BufferedReader(tmp);
		    String str;
		    StringBuffer buf=new StringBuffer();
		    
		    try {
				while ((str = reader.readLine()) != null) {
				  buf.append(str+"\n");
				}
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		    
		    try {
				fileStream.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		    System.out.println(buf);
		  }
		
		return names;
	}
}
